<?php

namespace App\Http\Controllers\Users;

use Aliyun\DySDKLite\SignatureHelper;
use App\Models\Admin;
use App\Models\ApplyRecord;
use App\Models\AttendanceAbroadModel;
use App\Models\BeforeMeeting;
use App\Models\LeaderTrialModel;
use EasyWeChat\Factory;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class BaseController extends Controller
{

    /**
     * 渲染视图
     * @param $view
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View+
     */
    protected function view($view,$data=[]){

//        //是否授权登录
//        if (!session()->has('wechat_user')) {
//            return redirect('wechat/oauth');
//        }

        return view(sprintf('%s.%s', config('wechat.route.prefix'), $view),$data);
    }

    /**
     * 内部重定向
     * @param $route
     * @param array $params
     * @param int $status
     * @param array $headers
     * @return \Illuminate\Http\RedirectResponse
     */
    protected function redirect($route, $params=[], $status=302, $headers=[]){
        return redirect()->route(sprintf('%s.%s', config('wechat.route.prefix'), $route), $params, $status, $headers);
    }

    /**
     * 返回json
     * @param bool $status
     * @param string $message
     * @param string $result
     * @return \Illuminate\Http\JsonResponse
     */
    protected function json($code = 0, $message = '', $result = ''){
        return response()->json([
            'code' => $code,
            'msg' => $message,
            'data' => $result
        ]);
    }

    /**
     * 生成订单号
     * @param string $str 字符串
     * @return string 订单号
     */
    public function GetOrderCode($str=''){
        $date = date('YmdHis')+80000;//时间相差8小时
        $str = $str?$str:$this->GetRandStr();
        $num = $this->GetRandStr();
        return $date.$str.$num;
    }

    /**
     * 获取配置
     * @param $name
     * @param string $type
     * @return mixed
     */
    public function get_config($name, $type='value')
    {
        $data = \DB::table('zd_config')->where('name', $name)->first();
        if ($data) {
            return $data->$type;
        }
    }

    /**
     * 验证码生成
     * @param string $len
     * @return mixed
     */
    public function GetRandStr($len = 6)
    {
        $chars = array(
            1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
        );
        $charsLen = count($chars) - 1;
        shuffle($chars);
        $output = "";
        for ($i = 0; $i < $len; $i++) {
            $output .= $chars[mt_rand(0, $charsLen)];
        }
        return $output;
    }

    /**
     * 生成随机字符串
     * @param string $device_id
     * @return string
     */
    public function get_random_str($device_id = '0123456789')
    {
        $device_id_ord = ord(substr($device_id, rand(0, strlen($device_id))));
        $guid = $this->guid();
        $str = substr($guid, rand(0, strlen($guid) - 2), 2);
        return str_pad(date('d') + date('m') + date('H') + date('i'), 3, '0', STR_PAD_RIGHT) . $device_id_ord . $str . substr(microtime(), 2, 5) . date('s') . sprintf('%02d', rand(0, 99));
    }

    /**
     * 获取随机ID
     * @param array $style
     * @return string
     */
    function guid($style = [])
    {
        if (function_exists('com_create_guid')) {
            return com_create_guid();
        } else {
            mt_srand((double)microtime() * 10000);//optional for php 4.2.0 and up.
            $charid = strtoupper(md5(uniqid(rand(), true)));
            $hyphen = @$style['dec'] ? chr(45) : '';// "-"
            $uuid = substr($charid, 0, 8) . $hyphen
                . substr($charid, 8, 4) . $hyphen
                . substr($charid, 12, 4) . $hyphen
                . substr($charid, 16, 4) . $hyphen
                . substr($charid, 20, 12);
            if (@$style['chr']) {
                $uuid = chr(123)// "{"
                    . $uuid
                    . chr(125);// "}"
            }
            return $uuid;
        }
    }

    /**
     * 阿里云短信
     * @param $phone
     * @param $TemplateCode
     * @param $code
     * @return bool
     */
    public function aliyunsms($phone,$TemplateCode,$code){
        $params = array ();
        // *** 需用户填写部分 ***
        //  必填: 请参阅 https://ak-console.aliyun.com/ 取得您的AK信息
        $accessKeyId = "LTAIKXwmCKsO0p6c";//"LTAIKNqsq0CJaG2U";
        $accessKeySecret = "cEfsHG7HNJSFYoVaMglXEFmk2euS9b";//"VKZCObTCXRSUJ5BEFHxLLeLRuiWIT1";
        //  必填: 短信接收号码
        $params["PhoneNumbers"] = $phone;
        //  必填: 短信签名，应严格按"签名名称"填写，请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign
        $qm = $this->get_config('SMS_QIAN_MING_STR');
        $params["SignName"] = $qm;//"约钱金服";
        //  必填: 短信模板Code，应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template
        $params["TemplateCode"] = $TemplateCode;
        //  可选: 设置模板参数, 假如模板中存在变量需要替换则为必填项
        $params['TemplateParam'] = Array (
            "code" =>$code,
        );
        // *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
        if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
            $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
        }
        // 初始化SignatureHelper实例用于设置参数，签名以及发送请求
        require_once base_path('app/Libs/aliyun_sms/SignatureHelper.php');
        $helper = new SignatureHelper();
        // 此处可能会抛出异常，注意catch
        $content = $helper->request(
            $accessKeyId,
            $accessKeySecret,
            "dysmsapi.aliyuncs.com",
            array_merge($params, array(
                "RegionId" => "cn-hangzhou",
                "Action" => "SendSms",
                "Version" => "2017-05-25",
            ))
        );
        if($content->Message=='OK'){
            return true;
        }else{
            return $content;
        }
    }


    /**
     * 执行post
     */
    function api_notice_increments($url, $data=[],$method='POST'){
        $ch = curl_init();
        $header[] = "Accept-Charset: utf-8";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $tmpInfo = curl_exec($ch);
        if (curl_errno($ch)) {
            curl_close( $ch );
            return $ch;
        }else{
            curl_close( $ch );
            return $tmpInfo;
        }

    }

    /**
     * 执行get
     * @param string $url
     * @return mixed
     */
    public function curl_get($url)
    {
        //初始化
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL,$url);
        // 执行后不直接打印出来
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        // 跳过证书检查
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // 不从证书中检查SSL加密算法是否存在
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        //执行并获取HTML文档内容
        $output = curl_exec($ch);

        //释放curl句柄
        curl_close($ch);

        return $output;
    }

    /**
     * 处理base64文件上传
     * @param $savepath 路劲
     * @param $img 图片
     * @param array $types
     * @return array
     */
    function SaveAjaxUpload($savepath, $img, $types=[]){
        $upload_path = 'uploads/';
        if(!is_dir(base_path().'/public_html/'.$upload_path)){
            mkdir(base_path().'/public_html/'.$upload_path);
        }
        $ad_path = $savepath;
        if(!is_dir(base_path().'/public_html/'.$upload_path.$ad_path)){
            mkdir(base_path().'/public_html/'.$upload_path.$ad_path);
        }
        $pic_url = $upload_path.$ad_path;
        $fullpath = $pic_url;
        $types = empty($types)? array('jpg', 'gif', 'png', 'jpeg'):$types;
        $img = str_replace(array('_','-'), array('/','+'), $img);
        $b64img = substr($img, 0,100);
        if(preg_match('/^(data:\s*image\/(\w+);base64,)/', $b64img, $matches)){
            $type = $matches[2];
            if(!in_array($type, $types)){
                return array('error'=>1,'msg'=>'图片格式不正确','url'=>'');
            }
            $img = str_replace($matches[1], '', $img);
            $img = base64_decode($img);
            $photo = '/'.time().rand(100000,999999).'.'.$type;
            file_put_contents($fullpath.$photo, $img);
            return array('error'=>0,'msg'=>'保存图片成功','url'=>$ad_path.$photo);
        }
        return array('error'=>1,'msg'=>'请选择要上传的图片','url'=>'');
    }

    /**
     * 二维数组排序
     * @param $arrays 数组
     * @param $sort_key 字段
     * @param int $sort_order 排序 SORT_ASC 升序 SORT_DESC 降序
     * @param int $sort_type 类型 SORT_STRING 字符串 SORT_NUMERIC 数字
     * @return bool
     */
    public function my_sort($arrays,$sort_key,$sort_order=SORT_ASC,$sort_type=SORT_NUMERIC){
        if(is_array($arrays)){
            foreach ($arrays as $array){
                if(is_array($array)){
                    $key_arrays[] = $array[$sort_key];
                }else{
                    return false;
                }
            }
        }else{
            return false;
        }
        array_multisort($key_arrays,$sort_order,$sort_type,$arrays);
        return $arrays;
    }

    /**
     * URL base64编码
     * '+' -> '-'
     * '/' -> '_'
     * '=' -> ''
     * @param unknown $string

     */
    public function urlsafe_b64encode($string) {
        $data = base64_encode($string);
        $data = str_replace(array('+','/','='),array('-','_',''),$data);
        return $data;
    }

    /**
     * URL base64解码
     * '-' -> '+'
     * '_' -> '/'
     * 字符串长度%4的余数，补'='
     * @param unknown $string
     */
    public static function urlsafe_b64decode($string) {
        $data = str_replace(array('-','_'),array('+','/'),$string);
        $mod4 = strlen($data) % 4;
        if ($mod4) {
            $data .= substr('====', $mod4);
        }
        return base64_decode($data);
    }

    /**
     * 支付宝支付订单生成
     * @param $order
     * @return \Yansongda\Pay\Gateways\Alipay\AppGateway
     */
    public function AliPays($order){

        $config = config('alipay.pay');

        $alipay = Pay::alipay($config);

        return $alipay->app($order);
    }

    //微信支付订单生成
    public function WxPays($order){
        $config = config('wxpay.pay');

        $wxpay = Pay::wechat($config);

        return $wxpay->app($order);
    }


    /**
     * 添加余额日志
     * @param $uid 用户
     * @param $money 金额
     * @param $status 1 增加 2 减少
     * @param $remark 备注
     * @param string $count_money 当前金额
     * @return bool
     */
    public function _add_money_log($uid,$money,$status=1,$remark='',$count_money=''){

        $date = date('Y-m-d H:i:s');

        if(!$count_money){

            $count_money = \DB::table('zd_users')

                ->where('id',$uid)

                ->value('balance');
        }

        $insert = [
            'uid'=>$uid,

            'money'=>$money,

            'count_money'=>$count_money,

            'remark'=>$remark,

            'status'=>$status,

            'regtime'=>time(),

            'created_at'=>$date,

            'updated_at'=>$date,
        ];

        $in = \DB::table('zd_user_money_log')

            ->insert($insert);

        if($in){

            return true;
        }

        return false;

    }


    /**
     * 添加用户消息
     * @param $uid 用户
     * @param $name 消息名称
     * @param $money 金额
     * @param $debit_id 借条id
     * @param int $type 类型 1 借款 2 销账
     * @return bool
     */
    public function _add_user_msg($uid,$name,$money,$debit_id,$type=1){

        $date = date('Y-m-d H:i:s');

        $table = 'zd_user_msgs';

        $insert = [

            'uid'=>$uid,

            'name'=>$name,

            'money'=>$money,

            'debit_id'=>$debit_id,

            'type'=>$type,

            'regtime'=>time(),

            'created_at'=>$date,

            'updated_at'=>$date,
        ];

        //修改用户新消息
        \DB::table('zd_users')

            ->where('id',$uid)

            ->update([
                'is_news'=>1,
            ]);

        $in = \DB::table($table)

            ->insert($insert);

        if($in){

            return true;
        }

        return false;

    }


    //借条余额增加抵扣
    public function user_money_handle($uid,$type=1,$money,$log=''){

        if(!$uid){

            return false;
        }

        $get_user = \DB::table('zd_users')

            ->where('id',$uid)

            ->first();

        //添加用户余额
        $count_money = $get_user->balance;

        if($type == 1){

            $count_money = bcadd($count_money,$money,2);
        }else{

            $count_money = bcsub($count_money,$money,2);
        }

        $up = \DB::table('zd_users')

            ->where('id',$uid)

            ->update([
                'balance'=>$count_money,

                'updated_at'=>date('Y-m-d H:i:s')
            ]);

        if($up){

            $this->_add_money_log($uid,$money,$type,$log,$count_money);

            return true;
        }

        return false;

    }



    //实名认证
    public function real_name_auth($data){

        $host = "https://api11.aliyun.venuscn.com";
        $path = "/cert/bank-card/4";
        $method = "GET";
        $appcode = "48dbcca4416c4d688bfe10385833d5d2";
        $headers = array();
        array_push($headers, "Authorization:APPCODE " . $appcode);
        $querys = "bank=".$data['card']."&mobile=".$data['phone']."&name=".$data['name']."&number=".$data['code']."&type=0";
        $bodys = "";
        $url = $host . $path . "?" . $querys;

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, false);
        if (1 == strpos("$".$host, "https://"))
        {
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        }

        return curl_exec($curl);
    }

    /**
     * 微信公众号推送消息
     * @param $uid
     * @param $status
     * @param array $data1
     * @param string $data_id
     * @return array|bool|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     */
    public function WxPushMsg($uid,$status,$data1=[],$data_id=''){

        if(!$uid){

            return false;
        }

        $user = Admin::checkCode($uid);

        if(!$user){

            return false;
        }

        $config = config('wechat.easy_wechat');

        $app = Factory::officialAccount($config);

        $openid = $user->openid;

        if(!$openid){

            return false;
        }

        $template_id = '';

        $url2 = 'wechat/';

        $data = [];

        switch ($status){
            case 1:// 外勤不固定打卡审核
                $template_id = 'XprX7YqdQ51mZVs5NzhB8pAZYjckK-kT6Ni09KGIT2I';
                $data['first'] = isset($data1['first'])?$data1['first']:'您有一条审核任务';
                $data['keyword1'] = $data1['keyword1'];//审核事项
                $data['keyword2'] = $data1['keyword2'];//审核内容
                $data['remark'] = '点击查看详情';

                $url2 = 'wechat/#/examineDetail?id='.$data_id.'&ptype=1';

                break;
            case 2://抽查审核
                $template_id = 'XprX7YqdQ51mZVs5NzhB8pAZYjckK-kT6Ni09KGIT2I';
                $data['first'] = isset($data1['first'])?$data1['first']:'您有一条审核任务';
                $data['keyword1'] = $data1['keyword1'];
                $data['keyword2'] = $data1['keyword2'];
                $data['remark'] = '点击查看详情';

                $url2 = 'wechat/#/examineDetail?id='.$data_id.'&ptype=1';
                break;
            case 3://缺卡说明审核
                $template_id = 'XprX7YqdQ51mZVs5NzhB8pAZYjckK-kT6Ni09KGIT2I';
                $data['first'] = isset($data1['first'])?$data1['first']:'您有一条审核任务';
                $data['keyword1'] = $data1['keyword1'];
                $data['keyword2'] = $data1['keyword2'];
                $data['remark'] = '点击查看详情';

                $url2 = 'wechat/#/examineDetail?id='.$data_id.'&ptype=1';
                break;
            case 4://请假审核通知审核
                $template_id = 'XprX7YqdQ51mZVs5NzhB8pAZYjckK-kT6Ni09KGIT2I';//'jJQMKZr4lJn7ZA1ys2jB4yKT1jdQgPi-lgFITxC76vU';
                $data['first'] = isset($data1['first'])?$data1['first']:'您有一条审核任务';
                $data['keyword1'] = $data1['keyword1'];
                $data['keyword2'] = $data1['keyword2'];
                $data['remark'] = '点击查看详情';

                $url2 = 'wechat/#/examineDetail?id='.$data_id.'&ptype=1';
                break;
            case 5://销假审核
                $template_id = 'XprX7YqdQ51mZVs5NzhB8pAZYjckK-kT6Ni09KGIT2I';
                $data['first'] = isset($data1['first'])?$data1['first']:'您有一条审核任务';
                $data['keyword1'] = $data1['keyword1'];
                $data['keyword2'] = $data1['keyword2'];
                $data['remark'] = '点击查看详情';
                $url2 = 'wechat/#/examineDetail?id='.$data_id.'&ptype=1';
                break;
            case 6://审核结果提醒
                $template_id = 'gzIo2NoJDa9sCKPomRUs-2hnlO49IVfCJTRWB0zMuSg';
                $data['first'] = isset($data1['first'])?$data1['first']:'您的审核已处理';
                $data['keyword1'] = $data1['keyword1'];//账号
                $data['keyword2'] = $data1['keyword2'];//审核时间
//                $data['remark'] = '点击查看详情';
                $url2 = 'wechat/#/examineDetail?id='.$data_id;
                break;
            case 7://会议通知
                $template_id = 'wz7Sf6BdpY3zPrhEHSF5gAu2t19CS9gxW573FoTTTcA';
                $data['first'] = isset($data1['first'])?$data1['first']:'您的审核已处理';
                $data['keyword1'] = $data1['keyword1'];//账号
                $data['keyword2'] = $data1['keyword2'];//审核时间
//                $data['remark'] = '点击查看详情';
                $url2 = 'wechat/#/meetDetail?id='.$data_id;
                break;
            case 8://缺卡通知
                $template_id = 'wz7Sf6BdpY3zPrhEHSF5gAu2t19CS9gxW573FoTTTcA';
                $data['first'] = isset($data1['first'])?$data1['first']:'缺卡通知';
                $data['keyword1'] = $data1['keyword1'];//
                $data['keyword2'] = $data1['keyword2'];//
                $data['remark'] = $data1['remark'];
                $url2 = isset($data1['url'])?$data1['url']:'';
                break;
            case 9://备忘提醒通知
                $template_id = 'wz7Sf6BdpY3zPrhEHSF5gAu2t19CS9gxW573FoTTTcA';
                $data['first'] = isset($data1['first'])?$data1['first']:'备忘提醒通知';
                $data['keyword1'] = $data1['keyword1'];//
                $data['keyword2'] = $data1['keyword2'];//
                $data['remark'] = $data1['remark'];
                $url2 = isset($data1['url'])?$data1['url']:'';
                break;
            case 10://审核结果通知
                $template_id = 'mo2R5yD4jYaWp81imeP6PwLcpCjadTtcd1z2tSp6YLk';
                $data['first'] = isset($data1['first'])?$data1['first']:'';
                $data['keyword1'] = $data1['keyword1'];//事项名称
                $data['keyword2'] = $data1['keyword2'];//反馈详情
                $data['remark'] = $data1['remark'];
                $url2 = isset($data1['url'])?$data1['url']:'';
                break;
            case 11://工作通知
                $template_id = 'bbyVPj6gteaY6Z0AgaXJbqMViOdFcvKcQmW7WhLvxUk';
                $data['first'] = isset($data1['first'])?$data1['first']:'';
                $data['keyword1'] = $data1['keyword1'];//工程名称
                $data['keyword2'] = $data1['keyword2'];//审核时间
                $data['remark'] = $data1['remark'];
                $url2 = isset($data1['url'])?$data1['url']:'';
                break;
            case 12:// 会议提醒
                $template_id = '17qPhzpnAPT9pZT9jp9fUNuEvA0MYXwIfkZdq-e_foA';
                $data['first'] = isset($data1['first'])?$data1['first']:'';
                $data['keyword1'] = $data1['keyword1'];//会议名称
                $data['keyword2'] = $data1['keyword2'];//会议时间
                $data['keyword3'] = $data1['keyword3'];//会议地点
                $data['remark'] = $data1['remark'];
                $url2 = isset($data1['url'])?$data1['url']:'wechat/#/meetDetail?id='.$data_id;
                break;
            case 13:// 签到提醒
                $template_id = '1ma13jG6cJKF3jsR5djAaTiDULfn0ipGUBVGJwLPKQ0';
                $data['first'] = isset($data1['first'])?$data1['first']:'';
                $data['keyword1'] = $data1['keyword1'];//签到姓名
                $data['keyword2'] = $data1['keyword2'];//签到内容
                $data['keyword3'] = $data1['keyword3'];//签到时间
                $data['remark'] = $data1['remark'];
                $url2 = isset($data1['url'])?$data1['url']:'wechat/#/checkCard';
                break;
            case 14:// 考勤结果通知
                $template_id = 'CTh4pPwyi2QUzQBdrGk2ji7UlOABjzltglVgvXzGo-0';
                $data['first'] = isset($data1['first'])?$data1['first']:'';
                $data['keyword1'] = $data1['keyword1'];//姓名
                $data['keyword2'] = $data1['keyword2'];//时间
                $data['keyword3'] = $data1['keyword3'];//考勤打卡详情
                $data['remark'] = $data1['remark'];
                $url2 = isset($data1['url'])?$data1['url']:'wechat/';
                break;
            case 15:// 工作提醒
                $template_id = 'lalB477utO2MZ6i7INaMhnZ_YXx2M7yCUtN7cs3Px3E';
                $data['first'] = isset($data1['first'])?$data1['first']:'';
                $data['keyword1'] = $data1['keyword1'];//任务编号
                $data['keyword2'] = $data1['keyword2'];//任务类型
                $data['keyword3'] = $data1['keyword3'];//任务描述
                $data['remark'] = $data1['remark'];
                $url2 = isset($data1['url'])?$data1['url']:'wechat/';
                break;
        }

        if(!$template_id){
            return false;
        }

        //测试
        if(config('app.url') == 'http://zd.ngrok.hanguosoft.com/'){
            $template_id = 'Bm5jmvxNFMIHugeO_lVWYlSCKewC9bQvs-d-lJoBWPI';
        }

        $url = config('app.url').$url2;

        return $app->template_message->send([
            'touser' => $openid,
            'template_id' => $template_id,
            'url' => $url,
            'data' => $data,
        ]);

    }


    /**
     * 中文首字母
     * @param $str
     * @return null|string
     */
    public function getFirstCharter($str)
    {
        if (empty($str)) {
            return '';
        }

        $fchar = ord($str{0});

        if ($fchar >= ord('A') && $fchar <= ord('z'))
            return strtoupper($str{0});

        $s1 = iconv('UTF-8', 'gb2312', $str);

        $s2 = iconv('gb2312', 'UTF-8', $s1);

        $s = $s2 == $str ? $s1 : $str;

        $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;

        if ($asc >= -20319 && $asc <= -20284)
            return 'A';

        if ($asc >= -20283 && $asc <= -19776)
            return 'B';

        if ($asc >= -19775 && $asc <= -19219)
            return 'C';

        if ($asc >= -19218 && $asc <= -18711)
            return 'D';

        if ($asc >= -18710 && $asc <= -18527)
            return 'E';

        if ($asc >= -18526 && $asc <= -18240)
            return 'F';

        if ($asc >= -18239 && $asc <= -17923)
            return 'G';

        if ($asc >= -17922 && $asc <= -17418)
            return 'H';

        if ($asc >= -17417 && $asc <= -16475)
            return 'J';

        if ($asc >= -16474 && $asc <= -16213)
            return 'K';

        if ($asc >= -16212 && $asc <= -15641)
            return 'L';

        if ($asc >= -15640 && $asc <= -15166)
            return 'M';

        if ($asc >= -15165 && $asc <= -14923)
            return 'N';

        if ($asc >= -14922 && $asc <= -14915)
            return 'O';

        if ($asc >= -14914 && $asc <= -14631)
            return 'P';

        if ($asc >= -14630 && $asc <= -14150)
            return 'Q';

        if ($asc >= -14149 && $asc <= -14091)
            return 'R';

        if ($asc >= -14090 && $asc <= -13319)
            return 'S';

        if ($asc >= -13318 && $asc <= -12839)
            return 'T';

        if ($asc >= -12838 && $asc <= -12557)
            return 'W';

        if ($asc >= -12556 && $asc <= -11848)
            return 'X';

        if ($asc >= -11847 && $asc <= -11056)
            return 'Y';

        if ($asc >= -11055 && $asc <= -10247)
            return 'Z';

        return null;

    }

    /**
     * PHP计算两个时间段是否有交集（边界重叠不算）
     *
     * @param string $beginTime1 开始时间1
     * @param string $endTime1 结束时间1
     * @param string $beginTime2 开始时间2
     * @param string $endTime2 结束时间2
     * @return bool
     * @author blog.snsgou.com
     */
    function is_time_cross($beginTime1 = '', $endTime1 = '', $beginTime2 = '', $endTime2 = '') {
        $status = $beginTime2 - $beginTime1;
        if ($status > 0) {
            $status2 = $beginTime2 - $endTime1;
            if ($status2 >= 0) {
                return false;
            } else {
                return true;
            }
        } else {
            $status2 = $endTime2 - $beginTime1;
            if ($status2 > 0) {
                return true;
            } else {
                return false;
            }
        }
    }

}
